import { Component } from '@angular/core';

declare var form: any;

@Component({
  templateUrl: './data.definition.html'
})
export class DataDefinitionComponent {

  public fs: any = null;
  public metadataDic: any = null;
  public layerTypeDic: any = null;
  public defDic: any = null;

  constructor() {
    this.fs = new form.FormSimpleService('datadefinition', {
      orderObject: { order: 0 },
      keyField: 'id'
    });
    // 加载表单数据
    this.fs.loadData(true);

    this.metadataDic = new form.DictionaryService('f_metadata_directory', this.filter);
    this.metadataDic.loadAll();

    this.layerTypeDic = new form.DictionaryService('d_table_type');

    // 数据定义
    this.defDic = new form.DictionaryService('g_data_definition');
    this.defDic.loadAll();
  }

  filter(data) {
    if (data) {
      const ri = [];
      for (let i = data.length - 1; i >= 0; i--) {
        const e = data[i];
        if (e.info && e.info === '2') {
          ri.push(i);
        }
      }
      ri.forEach((j) => {
        data.splice(j, 1);
      });
    }
    return data;
  }
}
